﻿Imports System.IO
Imports System.Text
Imports Pop.Api
Imports Pop.Api.Util
Imports Pop.Api.Request

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        'BodyBox.Text = MD5_Test()
        'BodyBox.Text = NewSign_Test()
        BodyBox.Text = Client_Test()
        'BodyBox.Text = NewClient_Test()
    End Sub

    ''' <summary>
    ''' 调用API测试
    ''' </summary>
    Private Function Client_Test() As String
        Dim client As IPopClient
        client = New DefaultPopClient("29230000ea0396dc0e4f81e4ba37a10c", "dtlhfu96u3wgrjpf03cobatmvjmqd2ug")

        Dim req As New SellerSearchItemListRequest
        req.SellerUin = 1637945321
        req.PageIndex = 1
        req.PageSize = 100
        req.ItemState = 2
        'req.Charset = "gbk"
        'req.Format = "xml"
        Dim res = client.Execute(req, 935686195, "3370c5370f2796dc0e4f46a0164e0bdf")
        Return res.Body
    End Function

    ''' <summary>
    ''' 调用API测试(新版)
    ''' </summary>
    Private Function NewClient_Test() As String
        Dim client As New OAuthPopClient("700044564", "UaHrcOHmYLMSx9Xr")
        'client.disableParser = True
        Dim req As New SellerSearchItemListRequest
        req.SellerUin = 1637945321
        req.PageIndex = 1
        req.PageSize = 100
        req.ItemState = 2
        Dim res = client.Execute(req, 935686195, "3370c5370f279d202b50962ab9d9e24f")
        Return res.Body
    End Function

    ''' <summary>
    ''' MD5加密测试 原文见:
    ''' http://pop.paipai.com/bin/view/Main/authorization
    ''' </summary>
    Private Function MD5_Test() As String
        Dim dic As New PopDictionary
        dic.Add("charset", "utf-8")
        dic.Add("xxx", "中文")
        dic.Add("yyy", "3")
        dic.Add("zzz", "2")
        Dim r As String = dic.GetDictionary.GetSign("module.action", "33230000e9030ghjtsfgh0564a0ce621")
        Return r
    End Function

    ''' <summary>
    ''' 新版权鉴测试 原文见:
    ''' http://pop.paipai.com/bin/view/Main/oauthsignmethod
    ''' </summary>
    Private Function NewSign_Test() As String
        Dim url As String = "http://api.paipai.com/deal/sellerSearchDealList.xhtml"
        Dim secretOAuthKey As String = "hdUMwmU4P5jQtHpC"

        Dim dic As New PopDictionary
        dic.Add("appOAuthID", "700042973")
        dic.Add("timeStamp", "1344568374452")
        dic.Add("accessToken", "ad39b7dbd59b87cda827223c0e520d6f")
        dic.Add("charset", "gbk")
        dic.Add("format", "xml")
        dic.Add("randomValue", "58095")
        dic.Add("uin", "1280863473")
        dic.Add("sellerUin", "1280863473")
        Return dic.GetNewSign(url, secretOAuthKey)
    End Function

End Class